package org.dromara.learning_lhz.controller;

import org.dromara.learning_lhz.entity.AsStudyQuestionsEntity;
import org.dromara.learning_lhz.entity.dto.AsStudyQuestionsDto;
import org.dromara.learning_lhz.service.StudyQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 题目控制器
 */
@RestController
@RequestMapping("/questions")
public class StudyQuestionsController {

    @Autowired
    private StudyQuestionsService studyQuestionsService;

    /**
     * 根据条件查询题目
     * @param asStudyQuestionsEntity 查询条件实体
     * @return 题目列表
     */
    @PostMapping("selQuestions")
    public List<AsStudyQuestionsEntity> selQuestions(@RequestBody AsStudyQuestionsEntity asStudyQuestionsEntity)
    {
        return studyQuestionsService.selQuestions(asStudyQuestionsEntity);
    }

    /**
     * 添加题目  (可以批量添加) 只能批量添加同种题目
     * @param asStudyQuestionsDto 题目数据传输对象
     */
    @PostMapping("addQuestions")
    public void addQuestions(@RequestBody AsStudyQuestionsDto asStudyQuestionsDto)
    {
        studyQuestionsService.addQuestions(asStudyQuestionsDto);
    }

    /**
     * 更新题目
     * @param asStudyQuestionsEntity 需要更新的题目实体
     */
    @PostMapping("updateQuestions")
    public void updateQuestions( @RequestBody AsStudyQuestionsEntity asStudyQuestionsEntity)
    {
        studyQuestionsService.updateById(asStudyQuestionsEntity);
    }

    /**
     * 删除题目
     * @param asStudyQuestionsEntity 需要删除的题目实体
     */
    @PostMapping("delQuestions")
    public void delQuestions( @RequestBody AsStudyQuestionsEntity asStudyQuestionsEntity)
    {
        studyQuestionsService.removeById(asStudyQuestionsEntity);
    }

}
